<?php
namespace view;

class HTMLCommentView {
    private $applicationModel;


    /**
    * __constructor
    */
    public function __construct()     {
        $this->applicationModel = new \model\ApplicationModel();
    }


    /**
    * @param String $blogHeader
    * @param String $blogText
    * @param String $blogDate
    * @param String $blogUser
    * @param String $comments
    * @var String $HTMLcomments
    * @return String HTML
    *
    * return -> visar kommentarer man skapat på just den blogposten
    */
    public function returnBlogPostCommentsPage($blogHeader, $blogText, $blogDate, $blogUser, $comments) {

        $HTMLcomments= "";

        if ($comments==false) {

             $numberOfComments = 0;
             $HTMLcomments = " <div class='showcomment'>
                                    <h3  class='commentuser'>No comments found</h3>
                                </div>";
        } else{

              foreach ($comments as $key => $row) {
                  $HTMLcomments .= " <div class='showcomment'>
                                         <h3>Created by: $row[1]</h3>
                                         <p>$row[2]</p>
                                         <div class='blogginlagg_datum'>Created: $row[3]</div>
                                         <div class='commentlank'>
                                         <a href='?".$this->applicationModel->m_editCommentURL."=$row[0]'>Edit comment</a>
                                         <a href='?".$this->applicationModel->m_deleteCommentURL."=$row[0]'>Remove comment</a>
                                         </div>
                                     </div>";
              }

              $numberOfComments = $key+1;
        }

        return "
        <div id='comment'>
                <h2>$blogHeader</h2>
                <p>$blogText</p>
                <div class='blogginlagg_creat'>Created by: $blogUser</div>
                <div class='blogginlagg_datum'>Date created: $blogDate</div>
                <h3>Comments ($numberOfComments) </h3>
                $HTMLcomments
         </div>";
    }


    /**
    * @param String $commentText
    * @return String HTML
    *
    * return -> visar medelar om att ny kommentar är registrerad skapad
    */
    public function returnSuccessfulCommentPage($commentText) {
        return "<div id='newcomment'><h2>New Comment registred Successful</h2>
                    <h2>New Comment</h2>
                        <p>$commentText</p>
                </div>";
    }


  	/**
    * @return String HTML
    *
    * return -> visar medelar om att kommentar är updaterad ändrad
    */
    public function returnSuccessfulUpdateCommentPage() {
        return "<h2>Comment updated Successfully!</h2>";
    }


  	/**
    * @return String HTML
    *
    * return -> visar meddelar om att kommentaren är borttagen
    */
	public function returnRemovedComment() {
        return "<h2>Comment Successfully removed</h2>";
    }


    /**
	* @return String HTML
	*/
	// return -> visar text "typ felmedelande"
    public function returnNotYourComment() {
        return "<h2>You cant remove/edit someone elses comment!</h2>";
    }


}

